// GameStart.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "GameStart.h"
#include "GameStartDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGameStartApp

BEGIN_MESSAGE_MAP(CGameStartApp, CWinApp)
	//{{AFX_MSG_MAP(CGameStartApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGameStartApp construction

CGameStartApp::CGameStartApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CGameStartApp object

CGameStartApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CGameStartApp initialization

BOOL CGameStartApp::InitInstance()
{
// 	if (!AfxSocketInit())
// 	{
// 		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
// 		return FALSE;
// 	}
	InitDictionary();
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	m_IniManager.InitInfo(_T("NetServer.ini"));
	m_IniManager.SetGroupName(_T("NetServer"));
	LoadParamConfig();

	CGameStartDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

int CGameStartApp::ExitInstance() 
{
	 ReleaseDictionary();
	return CWinApp::ExitInstance();
}

void CGameStartApp::LoadParamConfig()
{
	m_serverConfig.MaxConnections=m_IniManager.GetIniValueLong(_T("MaxConnections"),_T("20")); 
	m_serverConfig.MaxFreeBuff=m_IniManager.GetIniValueLong(_T("MaxFreeBuff"),_T("0"));
	m_serverConfig.MaxFreeContext=m_IniManager.GetIniValueLong(_T("MaxFreeContext"),_T("0"));
	m_serverConfig.IOWorkers=m_IniManager.GetIniValueLong(_T("IOWorkers"),_T("1"));
	m_serverConfig.LogicalWorkers=m_IniManager.GetIniValueLong(_T("LogicalWorkers"),_T("0"));
	m_serverConfig.Port=m_IniManager.GetIniValueLong(_T("Port"),_T("-1"));
	m_serverConfig.ReadInOrder=m_IniManager.GetIniValueLong(_T("ReadInOrder"),_T("1"));
	m_serverConfig.SendInOrder=m_IniManager.GetIniValueLong(_T("SendInOrder"),_T("1"));
	m_serverConfig.PendlingReads=m_IniManager.GetIniValueLong(_T("PendlingReads"),_T("4"));
	m_IniManager.GetIniValue(_T("tcServerIP"),_T("127.0.0.1"),m_serverConfig.tcServerIP,16);
	m_serverConfig.ServerPort=m_IniManager.GetIniValueLong(_T("ServerPort"),_T("999"));
}